import java.util.*;
import java.io.*;
public class 大鱼吃小鱼 {

    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 100001;
    public static int[][] stack = new int[MAXN][2]; // 0 下标, 1 轮数
    public static int[] arr = new int[MAXN];
    public static int r,n;
    public static void main(String[] args) throws IOException {
        n = in.nextInt();
        r = 0;
        int ans = 0;
        for (int i = 0;i < n;i++) {
            arr[i] = in.nextInt();
        }

        for (int i = n - 1,cur;i >= 0;i--) {
            cur = 0;
            while (r > 0 && arr[stack[r - 1][0]] < arr[i]) {
                cur = Math.max(cur + 1,stack[--r][1]); // 拿到轮数
            }
            stack[r][0] = i;
            stack[r++][1] = cur;
            ans = Math.max(cur,ans);
        }
        out.println(ans);
        out.close();
    }



    public static class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}
